<?php

namespace App\Http\Controllers\Internal;

use App\Models\UserStatus;
use App\Models\UserCourse;
use App\Models\LevelWord;

class UserStatusController extends Controller
{
    /*
     * @api get /internal/user-status/{userId}/level-evaluate 是否发送英语水平评测消息
     * @version 0.0.1
     * @group internal
     *
     * @response 200 正常结果 {
     *  "code":0,
     *  "msg":"",
     *  "data":{
     *  }
     * }
     */
    public function ifPushLevelEvaluate($userId)
    {
        $testLevel = UserStatus::where('user_id', $userId)->value('test_level');
        if ($testLevel) {
            return $this->sendSuccessJson();
        }

        $userCourses = UserCourse::where('user_id', $userId)->count();
        if ($userCourses) {
            return $this->sendSuccessJson();
        }

        $wordCount = LevelWord::count();

        return $this->sendSuccessJson([
            'wordCount' => $wordCount,
        ]);
    }
}